home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <regex.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
-
- #define BUF 4096
- int sockfd;
- int port;
- struct sockaddr_in eyepee;
- char *host;
-
- int main(int argc, char *argv[])
- {
- int readresult = 0;
- int scriptresult = 0;
- int executeresult = 0;
- int dirresult = 0;
- char dir[50];
-
- if (argc != 4) {
- fprintf(stderr, "Usage: %s <ip.ip.ip.ip> <port> <dir>\n", argv[0]);
- exit(8);
- }
-
- strncpy(dir, argv[3], sizeof(dir));
-
- eyepee.sin_family = AF_INET;
- eyepee.sin_port = htons(atoi(argv[2]));
- inet_aton(argv[1], &eyepee.sin_addr);
- host = argv[1];
-
- readresult = readaccess(dir);
- if (readresult == 1) {
- printf("Read Access is Allowed for this Directory\n");
- } else {
- printf("Read Access is Forbidden for this Directory\n");
- }
-
- scriptresult = scriptaccess(dir);
- if (scriptresult == 1) {
- printf("Script Access is Allowed for this Directory\n");
- } else {
- printf("Script Access is Forbidden for this Directory\n");
- }
-
- executeresult = executeaccess(dir);
- if (executeresult == 1) {
- printf("Execute Access is Allowed for this Directory\n");
- } else {
- printf("Execute Access is Forbidden for this Directory\n");
- }
-
- dirresult = dirlist(dir,argv[1]);
- if (dirresult == 1) {
- printf("Directory Listing is Allowed for this Directory\n");
- } else {
- printf("Directory Listing is Forbidden for this Directory\n");
- }
-
- return(0);
- }
-
-
- int readaccess(char *dir)
- {
- char sendbuf[125];
- char recvbuffer[BUF];
- char *http_resp;
- char *rec_sptr;
-
- if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- {
- perror("socket");
- exit(1);
- }
-
- if(connect(sockfd, (struct sockaddr *) &eyepee, sizeof(eyepee)) < 0)
- {
- perror("connect");
- }
-
- snprintf(sendbuf, 100, "GET %s/no-file.txt HTTP/1.0 \x0A\x0D\x0A\x0D",dir);
-
- send(sockfd, sendbuf, strlen(sendbuf),0);
- recv(sockfd, recvbuffer,sizeof(recvbuffer),0);
-
- http_resp = recvbuffer;
- rec_sptr = strchr(recvbuffer, '\n');
-
- *rec_sptr = '\0';
- ++rec_sptr;
-
- if(strncmp(http_resp, "HTTP/1.1 404 404 Object Not Found", 33) == 0) {
- printf("404 Not Found\n");
- close(sockfd);
- return (1);
- } else if(strncmp(http_resp, "HTTP/1.1 403 Access Forbidden",29) == 0) {
- printf("403 Access Forbidden\n");
- close(sockfd);
- return (0);
- }
- }
-
- int scriptaccess(char *dir)
- {
- char sendbuf[125];
- char recvbuffer[BUF];
- char *http_resp;
- char *rec_sptr;
-
- if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- {
- perror("socket");
- exit(1);
- }
-
- if(connect(sockfd, (struct sockaddr *) &eyepee, sizeof(eyepee)) < 0)
- {
- perror("connect");
- }
-
- snprintf(sendbuf, 100, "GET %s/no-file.asp HTTP/1.0 \x0A\x0D\x0A\x0D",dir);
-
- send(sockfd, sendbuf, strlen(sendbuf),0);
- recv(sockfd, recvbuffer,sizeof(recvbuffer),0);
-
- http_resp = recvbuffer;
- rec_sptr = strchr(recvbuffer, '\n');
-
- *rec_sptr = '\0';
- ++rec_sptr;
-
- if(strncmp(http_resp, "HTTP/1.1 404 404 Object Not Found", 33) == 0) {
- printf("404 Not Found\n");
- close(sockfd);
- return (1);
- } else if(strncmp(http_resp, "HTTP/1.1 403 Access Forbidden",29) == 0) {
- printf("403 Access Forbidden\n");
- close(sockfd);
- return (0);
- }
- }
-
- int executeaccess(char *dir)
- {
- char sendbuf[125];
- char recvbuffer[BUF];
- char *http_resp;
- char *rec_sptr;
-
- if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- {
- perror("socket");
- exit(1);
- }
-
- if(connect(sockfd, (struct sockaddr *) &eyepee, sizeof(eyepee)) < 0)
- {
- perror("connect");
- }
-
- snprintf(sendbuf, 100, "GET %s/no-file.dll HTTP/1.0 \x0A\x0D\x0A\x0D",dir);
-
- send(sockfd, sendbuf, strlen(sendbuf),0);
- recv(sockfd, recvbuffer,sizeof(recvbuffer),0);
-
- http_resp = recvbuffer;
- rec_sptr = strchr(recvbuffer, '\n');
-
- *rec_sptr = '\0';
- ++rec_sptr;
-
- if(strncmp(http_resp, "HTTP/1.1 500 Server Error",25) == 0) {
- printf("500 Server Error\n");
- close(sockfd);
- return (1);
- } else if(strncmp(http_resp, "HTTP/1.1 404 404 Object Not Found", 33) == 0) {
- printf("404 Object Not Found\n");
- close(sockfd);
- return (0);
- }
- }
-
- int dirlist(char *dir, char *host)
- {
- char sendbuf[200];
- char recvbuffer[BUF];
- int status;
- regex_t re;
- char *pattern = "[To Parent Directory]";
- if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- {
- perror("socket");
- exit(1);
- }
-
- if(connect(sockfd, (struct sockaddr *) &eyepee, sizeof(eyepee)) < 0)
- {
- perror("connect");
- }
-
-
- snprintf(sendbuf, 200, "GET %s HTTP/1.0 \r\nAccept-Language: en-us\r\nUser-Agent: Mozilla/4.0\r\nHost: %s\r\nConnection: Keep-Alive\r\n\r\n", dir, host);
-
- send(sockfd, sendbuf, strlen(sendbuf),0);
- recv(sockfd, recvbuffer,sizeof(recvbuffer),0);
- recv(sockfd, recvbuffer,sizeof(recvbuffer),0);
- close(sockfd);
-
-
- if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) {
- return(0);
- }
- status = regexec(&re, recvbuffer, (size_t) 0, NULL, 0);
- regfree(&re);
- if (status != 0) {
- return(0);
- }
- return (1);
- }
-